package cn.ac.siom.query.dao.impl;

import cn.ac.siom.query.dao.IItem_infoDAO;
import cn.ac.siom.query.vo.Item_info;

import cn.ac.siom.query.vo.Tab_Thesis;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Repository
public class Item_infoDAOImpl extends SqlSessionDaoSupport implements IItem_infoDAO {
    @Autowired
    public Item_infoDAOImpl(SqlSessionFactory sqlSessionFactory){
        super.setSqlSessionFactory(sqlSessionFactory);
    }
    @Override
    public boolean doCreate(Item_info vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doUpdate(Item_info vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doRemove(Set<?> ids) throws SQLException {
        return false;
    }

    @Override
    public Item_info findById(Integer id) throws SQLException {
        return null;
    }

    @Override
    public List<Item_info> findAll() throws SQLException {
        return super.getSqlSession().selectList("Item_infoNS.findAll");
    }

    @Override
    public List<Item_info> findAllBySplit(String column, String keyWord, Integer currentPage, Integer lineSize) throws SQLException {
        return null;
    }

    @Override
    public List<Item_info> findNo(Integer id ) throws SQLException {
        Map<String, Integer> map= new HashMap<>();
        map.put("i_id",id);
        return super.getSqlSession().selectList("Item_infoNS.findNo", map);
    }

    @Override
    public List<Item_info> findPage(Integer rownum,Integer page_id) throws SQLException {
        page_id=rownum*(page_id-1);
        Map<String, Integer> map= new HashMap<>();
        map.put("page_id",page_id);
        map.put("rownum",rownum);
        return super.getSqlSession().selectList("Item_infoNS.findPage", map);
    }

    @Override
    public Integer findCount() throws SQLException {
        return super.getSqlSession().selectOne("Item_infoNS.findCount");
    }

    @Override
    public List<Tab_Thesis> find_Thesis(Integer page_id, Integer i_id) throws SQLException {
        Integer startRow=(page_id-1)*20;
        Integer endRow=(page_id-1)*20+20;
        Map<String, Integer> map= new HashMap<>();
        map.put("startRow",startRow);
        map.put("endRow",endRow);
        map.put("page_id",page_id);
        map.put("i_id",i_id);
        return super.getSqlSession().selectList("Item_infoNS.findThesis", map);
    }

    @Override
    public Integer find_Thesis_count(Integer i_id) throws SQLException {
        Map<String, Integer> map= new HashMap<>();
        map.put("i_id",i_id);
        return super.getSqlSession().selectOne("Item_infoNS.findThesis_Count", map);
    }

    @Override
    public List<Item_info> findWords(String words) throws SQLException {
        Map<String, String> map= new HashMap<>();
        map.put("words",words);
        return super.getSqlSession().selectList("Item_infoNS.findWords",map);
    }
}
